package helmsvc

import (
	corev1 "gluenet/internal/agent/api/core/v1"
	"gluenet/internal/agent/cache/object"
	"gluenet/internal/agent/depend"
	"gluenet/internal/agent/driver/helmdriver"
	"gluenet/internal/agent/driver/k8sdriver"
	v1 "gluenet/pkg/log/v1"

	"github.com/spf13/viper"
)

func init() {
	depend.Provide(NewService)
	depend.Provide(NewJaegerRelease)
}

type Service struct {
	logger v1.Logger

	hd helmdriver.HelmDriver
	kd k8sdriver.K8sDriver

	objects object.Interface

	jaegerRelease *JaegerRelease
}

func NewService(
	hd helmdriver.HelmDriver,
	kd k8sdriver.K8sDriver,
	objs object.Interface,
	jaegerRelease *JaegerRelease,
) *Service {

	return &Service{
		logger:        v1.NewLogger(""),
		objects:       objs,
		hd:            hd,
		kd:            kd,
		jaegerRelease: jaegerRelease,
	}
}

const (
	keyJaegaerChart  = `monitor.chart.jaeger.chart`
	keyJaegerRelease = `monitor.chart.jaeger.release`
)

type JaegerRelease struct {
	corev1.Release
}

func NewJaegerRelease(vp *viper.Viper) *JaegerRelease {
	chartName := vp.GetString(keyJaegaerChart)
	if chartName == "" {
		chartName = "gluenet.io/jaeger-all-in-one"
	}

	releaseName := vp.GetString(keyJaegaerChart)
	if releaseName == "" {
		releaseName = "glue-jaeger-all-in-one"
	}

	return &JaegerRelease{
		corev1.Release{
			ChartName:   chartName,
			ReleaseName: releaseName,
		},
	}
}
